package com.xb.controller;

import com.xb.entity.Announcement;
import com.xb.service.IAnnouncementService;
import com.xb.util.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Controller
 * /api/announcement
 */
@RestController
@RequestMapping("/api/announcement")
public class AnnouncementController {
    @Autowired
    private IAnnouncementService announcementService;


    @GetMapping
    public Result selectAllAnn(@RequestParam("annStatus") int annStatus){
        Result result = new Result();
        List<Announcement> announcements = announcementService.selectAnnouncementListByStatus(annStatus);
        result.setData(announcements);
        return  result;
    }

    @RequestMapping("/page")
    @RequiresPermissions("system:announcement:page")
    public Object findPage(Announcement obj,@RequestParam(value = "page",defaultValue = "1")Integer page,
                           @RequestParam(value = "limit",defaultValue = "10")Integer limit) {
        return announcementService.selectAnnouncementList(obj, page, limit);
    }

    /**
     * 添加
     */
    @PostMapping
    @RequiresPermissions("system:announcement:add")
    public Object add(@RequestBody Announcement obj) {
        return announcementService.insertAnnouncement(obj);
    }

    /**
     * 修改
     */
    @PutMapping
    @RequiresPermissions("system:announcement:update")
    public Object update(@RequestBody Announcement obj) {
        return announcementService.updateAnnouncement(obj);
    }
    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @RequiresPermissions("system:announcement:del")
    public Object del(@PathVariable Integer id) {
        return announcementService.deleteAnnouncementById(id);
    }

}
